#ifndef _IMAGE_H
#define _IMAGE_H

namespace RAYTRACER
{
class TGA
{
public :
	TGA (const char * filename) 
	{
		this->imageFile.open(filename, ios_base::binary);
	}
	void writeHeadUnCompressed(int width, int height)
	{
		// Addition of the TGA header
		imageFile.put(0).put(0);
		imageFile.put(2);        /* RGB not compressed */

		imageFile.put(0).put(0);
		imageFile.put(0).put(0);
		imageFile.put(0);

		imageFile.put(0).put(0); /* origin X */ 
		imageFile.put(0).put(0); /* origin Y */

		imageFile.put((unsigned char)(width & 0x00FF)).put((unsigned char)((width & 0xFF00) / 256));
		imageFile.put((unsigned char)(height & 0x00FF)).put((unsigned char)((height & 0xFF00) / 256));
		imageFile.put(24);       /* 24 bit bitmap */ 
		imageFile.put(0); 
	}
	void writePixel (const Color & c)
	{
		imageFile.put((unsigned char)min(c.blue*255.0f,255.0f)).put((unsigned char)min(c.green*255.0f, 255.0f)).put((unsigned char)min(c.red*255.0f, 255.0f));
		//imageFile.put((unsigned char) c.getShortChannel(OFFSET_BLUE)).put((unsigned char) c.getShortChannel(OFFSET_GREEN)).put((unsigned char) c.getShortChannel(OFFSET_RED));
	}
	void writePixel (float & red, float & green, float & blue)
	{
		writePixel(Color (red, green, blue));
	}
private:
	ofstream imageFile ;
};

}
#endif
